package com.plate.auth.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.plate.common.core.result.Result;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName ResponseUtils
 * @Description 请求返回结果封装类
 * @Author jiaxd
 * @Date 2023年10月29日 18:26
 * @Version 1.0
 */

public class ResponseUtils {

    public static void result(HttpServletResponse response, Result result) throws IOException {
        response.setContentType("application/json;charset=UTF-8");
        ServletOutputStream out = response.getOutputStream();
        ObjectMapper objectMapper = new ObjectMapper();
        out.write(objectMapper.writeValueAsString(result).getBytes("UTF-8"));
        out.flush();
        out.close();
    }

}
